package cn.tedu.boyou.mgrsite.controller;

import cn.tedu.boyou.acticle.domain.StrategyDetail;
import cn.tedu.boyou.acticle.service.*;
import cn.tedu.boyou.common.query.StrategyDetailQuery;
import cn.tedu.boyou.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyDetail")
public class StrategyDetailController {

    @Reference
    private IStrategyDetailService strategyDetailService;
    @Reference
    private IStrategyService strategyService;
    @Reference
    private IStrategyThemeService strategyThemeService;

    @Reference
    private IStrategyCatalogService strategyCatalogService;

    @Reference
    private IStrategyTagService strategyTagService;


    @Value("${file.path}")
    private String path;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")StrategyDetailQuery qo){
        model.addAttribute("pageInfo",strategyDetailService.query(qo));
        return "strategyDetail/list";
    }

    @RequestMapping("/input")
    public String input(Model model,Long id){
        if(id != null){
            model.addAttribute("strategyDetail",strategyDetailService.get(id));
            model.addAttribute("tags",strategyTagService.selectTagsByDetailId(id));
        }
        //strategies
        model.addAttribute("strategies",strategyService.listAll());
        //themes
        model.addAttribute("themes",strategyThemeService.listAll());
        return "strategyDetail/input";
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        strategyDetailService.delete(id);
        return new AjaxResult();
    }

    //getCatalogByStrategyId
    @RequestMapping("/getCatalogByStrategyId")
    @ResponseBody
    public Object getCatalogByStrategyId(Long strategyId){
        return strategyCatalogService.selectCatalogByStrategyId(strategyId);
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyDetail strategyDetail, String[] tags){
        strategyDetailService.saveOrUpdate(strategyDetail,tags);
        return new AjaxResult();
    }


    //changeState
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(Integer state,Long id){
        strategyDetailService.changeState(state,id);
        return new AjaxResult();
    }




}
